import React from "react";

export default class ErrorBoundary extends React.Component {
  constructor(props) {
    super(props);
    this.state = { hasError: false };
  }

  static getDerivedStateFromError(error) {
    return { hasError: true };
  }

  componentDidCatch(error, errorInfo) {
    // console.warn(error, errorInfo);
  }

  render() {
    if (this.state.hasError) {
      return <span style={{ color: "red" }}>组件配置或数据类型错误</span>;
    }
    return this.props.children;
  }
}
